#pragma once
#include "RBTree.h"

using namespace std;

namespace exercise
{
	template<class K,class V>
	class map
	{
		struct KeyOfT
		{
			K operator()(const pair<const K, V>& s)
			{
				return s.first;
			}
		};


	public:
		typedef typename RBTree<K, pair<const K, V>, KeyOfT>::Iterator  iterator;
		typedef typename RBTree<K, pair<const K, V>, KeyOfT>::Const_Iterator  const_iterator;


		pair<iterator,bool> insert(const pair<const K,V>& val)
		{
			return t.Insert(val);
		}

		iterator begin()
		{
			return t.begin();
		}

		iterator end()
		{
			return t.end();
		}

		const_iterator begin() const
		{
			return t.begin();
		}

		const_iterator end() const
		{
			return t.end();
		}

		iterator find(const K& k)
		{
			return t.Find(k);
		}

		V& operator[](const K& key)
		{

			pair<iterator, bool> ret = t.Insert(make_pair(key, V()));
		
			return ret.first->second;
		}



	private:
		RBTree<K, pair<const K, V>, KeyOfT> t;
	};
}